package com.bestv.database.dao;

import com.bestv.database.vo.IncrProgram;
import com.bestv.utils.database.DBConnectionManager;
import com.bestv.utils.database.JDBCHelper;

import java.sql.Connection;
import java.util.List;

/**
 * Created by Henry on 14-7-10.
 */
public class IncrProgramDao {
    public void truncate() {
        Connection conn = DBConnectionManager.getMasterConnection();
        String sql = "TRUNCATE incr_program";
        JDBCHelper.executeUpdate(conn, sql);
    }

    public void saveBatch(List<IncrProgram> programs) {
        Object[][] matrix = new Object[programs.size()][3];
        for (int i=0; i<programs.size(); i++) {
            IncrProgram program = programs.get(i);
            Object[] array = new Object[3];
            array[0] = program.getMediaCode();
            array[1] = program.getName();
            array[2] = program.getSeriesCode();
            matrix[i] = array;
        }
        Connection conn = DBConnectionManager.getMasterConnection();
        String sql = "INSERT INTO incr_program (MediaCode, Name, SeriesCode) VALUES (?, ?, ?)";
        JDBCHelper.executeBatch(conn, sql, matrix);
    }
}
